import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import 'antd/dist/antd.css'
import zhCN from 'antd/es/locale/zh_CN'
import { ConfigProvider } from 'antd'
import { HashRouter as Router,Route , Switch,Redirect  } from 'react-router-dom'
import {baseRoutes } from "./routes"
import { Provider } from 'react-redux'
import store from "./store"
import Login from "./views/Login"
ReactDOM.render(
  <Router>
    <Provider store = {store}>
		<ConfigProvider locale={zhCN}>
		  {/* 渲染基础路由 */}
		  <Switch>
		    {
		      baseRoutes.map(el=>{
		        return (
		          <Route key={el.path}
		          path={ el.path }
		          component={el.component}/>
		        )
		      })
		    }
		    <Route path="/admin" render={ (routerProps)=>{
				return (
					// 判断用户是否登录
					// 判断有无token
					localStorage.getItem("token")
					?
					<App {...routerProps}/>
					:
					<Redirect to="/login"/>
				)
			} }/>
		    <Redirect to="/admin" from="/" exact/>
		    <Redirect to="/404"/>
		  </Switch>
		</ConfigProvider>
	</Provider>
  </Router>
,
  document.getElementById('root')
);


